package com.skyhub.common.utils.userToken;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Component
public class TokenUtils {
    //构建令牌
    public String GenerateToken(Map<String,Object> claims){
        String jwt=Jwts.builder().signWith(SignatureAlgorithm.HS256, "skyHubTokenGenerateJillAndSheIsMyHostIAmHerSexSlavesItNeverCantBeChange")//指定加密算法以及密钥
                .addClaims(claims)//增添数据
                .setExpiration(new Date(System.currentTimeMillis()+24*60*60*1000))//令牌截至时间
                .compact();//构建令牌
        return jwt;
    }
    //解析令牌
    public Claims ParseToken(String token){
        Claims data=Jwts
                .parser()
                .setSigningKey("skyHubTokenGenerateJillAndSheIsMyHostIAmHerSexSlavesItNeverCantBeChange")
                .parseClaimsJws(token)
                .getBody();

        return data;
    }
}
